package com.test.generic.testC;

import org.apache.commons.lang3.reflect.FieldUtils;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: yangzhiwei
 * @Date: 2021/3/5 16:37
 */
public class GrandFather<T extends  Father> {
    List<T> list;

    public void getGenericType (List<T> list) throws NoSuchFieldException {
       // Field field = FieldUtils.getField(list,get)
        this.list = list;
        Field field = FieldUtils.getField(GrandFather.class, "a3");
        System.out.println(((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]);



        Type[] type = ((ParameterizedType) (list.getClass().getGenericSuperclass())).getActualTypeArguments();
        System.out.println(type[0]);
    }

    public static void main(String[] args) throws NoSuchFieldException {
        GrandFather<Father> grandFather = new GrandFather<>();
        ArrayList<Father> fathers = new ArrayList<>();
        grandFather.getGenericType(fathers);
    }
}
